//
//  LGFollowOperationCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/25.
//  手术记录

#import "LGFollowOperationRecordCell.h"

@interface LGFollowOperationRecordCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UIButton *editButton;
/**   */
@property (nonatomic , strong)UIButton *checkButton;
/**   */
@property (nonatomic , strong)UIView *lineView;

@end

@implementation LGFollowOperationRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.titleLabel.text = LGNSString(dataDic[@"shouss_name"]);
    self.dateLabel.text = LGNSString(dataDic[@"shouss_date"]);
    if([LGNSString(dataDic[@"record_id"]) length]>0){
        //有报告
        self.checkButton.selected = YES;
        self.checkButton.userInteractionEnabled = YES;
        self.checkButton.layer.borderColor = [UIColor colorWithString:@"#3291FF"].CGColor;
    }else{
        self.checkButton.selected = NO;
        self.checkButton.userInteractionEnabled = NO;
        self.checkButton.layer.borderColor = [UIColor colorWithString:@"#999999"].CGColor;
    }
}

-(void)editButtonAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(editOperationRecord:)]){
        [self.delegate editOperationRecord:self.index];
    }
}

-(void)checkButtonAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(checkOperationRecord:)]){
        [self.delegate checkOperationRecord:self.dataDic];
    }
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.dateLabel];
    [self.contentView addSubview:self.editButton];
    [self.contentView addSubview:self.checkButton];
    [self.contentView addSubview:self.lineView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(12));
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(120));
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.top.equalTo(self.titleLabel);
        make.height.equalTo(@(20));
    }];
    
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(16));
        make.right.equalTo(self.checkButton.mas_left).offset(-viewPix(12));
        make.bottom.equalTo(self.contentView).offset(-viewPix(12));
        make.width.equalTo(@(78));
        make.height.equalTo(@(32));
    }];
    [self.checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(32));
        make.centerY.height.equalTo(self.editButton);
        make.width.equalTo(@(100));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _titleLabel;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _dateLabel;
}

-(UIButton *)editButton{
    if(!_editButton){
        _editButton = [UIButton buttonWithTitle:@"编辑" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#3291FF" imageName:@""];
        _editButton.layer.borderColor = [UIColor colorWithString:@"#3291FF"].CGColor;
        _editButton.layer.borderWidth = 1;
        _editButton.cornerRidus = 16;
        [_editButton addTarget:self action:@selector(editButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editButton;
}

-(UIButton *)checkButton{
    if(!_checkButton){
        _checkButton = [UIButton buttonWithTitle:@"查看报告" titleFont:LGFontWeight(15, UIFontWeightMedium) normalColor:@"#999999" selectColor:@"#3291FF"];
        _checkButton.layer.borderColor = [UIColor colorWithString:@"#999999"].CGColor;
        _checkButton.layer.borderWidth = 1;
        _checkButton.cornerRidus = 16;
        [_checkButton addTarget:self action:@selector(checkButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _checkButton;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
